// Copyright (C) <2018> Zealcomm Inc.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IRTC_CONFERENCE_OBJC_IRTCCONFERENCECLIENT_H_
#define IRTC_CONFERENCE_OBJC_IRTCCONFERENCECLIENT_H_
#import <WebRTC/RTCMacros.h>
#import "IRTC/IRTCConferenceClientConfiguration.h"
#import "IRTC/IRTCConferencePublication.h"
#import "IRTC/IRTCConferenceSubscription.h"
#import "IRTC/IRTCConferenceParticipant.h"
#import "IRTC/IRTCConferenceInfo.h"
#import "IRTC/IRTCLocalStream.h"
#import "IRTC/IRTCRemoteMixedStream.h"
#import "IRTC/IRTCRemoteStream.h"
#import "IRTC/IRTCPublishOptions.h"
NS_ASSUME_NONNULL_BEGIN
@protocol IRTCConferenceClientDelegate;
/// An asynchronous class for app to communicate with a conference in MCU.<br>用于和MCU的会议进行联系的异步类。
RTC_EXPORT
@interface IRTCConferenceClient : NSObject
/**
  @brief Initialize a IRTCConferenceClient with configuration.<br>用配置来初始化IRTCConferenceClient。
  @param config Configuration for creating the IRTCConferenceClient.<br>用于创建IRTCConferenceClient的配置参数。
*/
- (instancetype)initWithConfiguration:(IRTCConferenceClientConfiguration*)config;
/**
  @brief Connect to the specified room to join a conference.<br>连接到某个房间以便加入会议。
  @param token Includes the room info which is encrypted.<br>房间令牌，里面包括加密后的房间信息。
  @param onSuccess Success callback with the conference info.<br>成功后的回调，含会议信息。
*/
- (void)joinWithToken:(NSString*)token
            onSuccess:(nullable void (^)(IRTCConferenceInfo*))onSuccess
            onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Publish the stream to the current room.<br>发布媒体流到当前房间。
  @param stream The stream to be published.<br>用于发布的媒体流。
*/
- (void)publish:(IRTCLocalStream*)stream
    withOptions:(nullable IRTCPublishOptions*)options
      onSuccess:(nullable void (^)(IRTCConferencePublication*))onSuccess
      onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Subscribe a stream from the current room.<br>从当前房间订阅媒体流。
  @param stream The remote stream to be subscribed.<br>将订阅的远端媒体流。
  @param options Options for subscribing the stream.<br>订阅媒体流时的参数。
  @param onSuccess Success callback with a stream that contains media stream.<br>成功后的回调，含订阅的媒体流。
*/
- (void)subscribe:(IRTCRemoteStream*)stream
      withOptions:(nullable IRTCConferenceSubscribeOptions*)options
        onSuccess:(nullable void (^)(IRTCConferenceSubscription*))onSuccess
        onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Send message to all participants in the conference.<br>给会议内所有与会者发送消息。
  @param message The message to be sent.<br>用于发送的消息。
*/
- (void)send:(NSString*)message
    onSuccess:(nullable void (^)())onSuccess
    onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Send message to specific participant in the conference.<br>给会议内指定与会者发送消息。
  @param message The message to be sent..<br>用于发送的消息。
  @param to The user who receives this message.<br>接收消息的用户。
*/
- (void)send:(NSString*)message
           to:(NSString*)receiver
    onSuccess:(nullable void (^)())onSuccess
    onFailure:(nullable void (^)(NSError*))onFailure;
/**
  @brief Leave current conference.<br>离开当前会议。
*/
- (void)leaveWithOnSuccess:(nullable void (^)())onSuccess
                 onFailure:(nullable void (^)(NSError*))onFailure;
@property(nonatomic, weak) id<IRTCConferenceClientDelegate> delegate;
@end
/// Delegate for IRTCConferenceClient.<br>IRTCConferenceClient的Delegate（代理）。
RTC_EXPORT
@protocol IRTCConferenceClientDelegate<NSObject>
@optional
/**
  @brief Triggers when client is disconnected from conference server.<br>当客户端和会议服务器断开连接时触发。
*/
- (void)conferenceClientDidDisconnect:(IRTCConferenceClient*)client;
/**
  @brief Triggers when a stream is added.<br>当有新的媒体流加入时触发。
  @param stream The stream which is added.<br>新加入的媒体流。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
            didAddStream:(IRTCRemoteStream*)stream;
/**
  @brief Triggers when a message is received.<br>当接收到新的消息时触发。
  @param senderId Sender's ID.<br>发送者的ID。
  @param message Message received.<br>接收到的消息。
  @param targetType "all" if broadcast message. "me"
  if the message is sent only to current conference client.<br>如果是"all"则是广播消息；如果是"me"则是指定发送目标的消息。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
       didReceiveMessage:(NSString*)message
                    from:(NSString*)senderId
                    to:(NSString*)targetType;
/**
  @brief Triggers when a user joined conference.<br>当有新的用户加入会议时触发。
  @param user The user joined.<br>新加入的用户。
*/
- (void)conferenceClient:(IRTCConferenceClient*)client
       didAddParticipant:(IRTCConferenceParticipant*)user;
@end
NS_ASSUME_NONNULL_END
#endif  // IRTC_CONFERENCE_OBJC_IRTCCONFERENCECLIENT_H_
